﻿using System;
using System.Collections.Generic;
using System.Text;
using TTClassLibrary;
using TTServer.Messages;
using libCommonClass;
using TTServer.Controller;
using libAsymmetricEncryption;
using libUtilities;

namespace TTServer.MessageProcessor
{
    public class NMSAuthentificationRequestMessageProcessor : IMessageProcessor
    {
        public bool Process(libCommonClass.TTMessage message, libInterface.IClientInfoProvider clientInfoProvider)
        {
            if (message is NMSAuthentificationRequestMessage)
            {
                NMSAuthentificationRequestMessage msg = (NMSAuthentificationRequestMessage)message;

                AuthenManagement authenManagement = AuthenManagement.getInstance();

                if (Global.bEnableNMS == false || authenManagement.isAvailable() == false)
                {
                    NMSAuthentificationResponseMessage res =
                        new NMSAuthentificationResponseMessage(NMSAuthentificationResponseMessage.TYPE_FAILED,
                            "N members system invailable now");

                    clientInfoProvider.AddToMessageQueue(res);
                }
                else
                {
                    authenManagement.AuthenticateNewMember(
                    ((NMSAuthentificationRequestMessage)msg).MemInfo, clientInfoProvider);
                }

                return true;
            }

            return false;
        }
    }
}
